﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using TestImpresion.Clases;

namespace TestImpresion.Controles
{
    public partial class ImprimirResultados : UserControl
    {
        private readonly DependencyProperty _datasourceProperty =
DependencyProperty.Register("Datasource", typeof(ImprentaFormulario), typeof(ImprimirResultados), new PropertyMetadata(new ImprentaFormulario()));

        [System.ComponentModel.Category("User properties")]
        [System.ComponentModel.Description("User Datasource")]
        public ImprentaFormulario Datasource
        {
            get { return (ImprentaFormulario)GetValue(_datasourceProperty); }
            set { SetValue(_datasourceProperty, value); }
        }

        public ImprimirResultados()
        {
            InitializeComponent();
        }

        private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            this.Datasource.ImprimeResultados();
            this.panelInterioes.Children.Clear();
            this.panelInsertos.Children.Clear();
            this.panelEncuadernado.Children.Clear();

            this.panelInterioes.Children.Add(this.GetPanelInformaciob("Páginas: ", this.Datasource.ValoresInterior.Paginas.ToString()));
            this.panelInterioes.Children.Add(this.GetPanelInformaciob("Papel: ", this.Datasource.ValoresInterior.Papel));
            this.panelInterioes.Children.Add(this.GetPanelInformaciob("Tintas: ", this.Datasource.ValoresInterior.Tintas));
            this.panelInterioes.Children.Add(this.GetPanelInformaciob("Acabados: ", "Ninguno"));
            var inserto = 1;
            foreach (var insertoInfo in this.Datasource.ValoresInsertos)
            {
                this.panelInsertos.Children.Add(this.GetPanelInformaciob("Inserto: ",inserto.ToString()));
                this.panelInsertos.Children.Add(this.GetPanelInformaciob("Páginas: ", insertoInfo.Paginas.ToString()));
                this.panelInsertos.Children.Add(this.GetPanelInformaciob("Papel: ", insertoInfo.Papel));
                this.panelInsertos.Children.Add(this.GetPanelInformaciob("Tintas: ", insertoInfo.Tintas));
                this.panelInsertos.Children.Add(this.GetPanelInformaciob("Acabados: ", "Ninguno",true));
                inserto++;
            }
            
            this.panelEncuadernado.Children.Add(this.GetPanelInformaciob("Papel: ", this.Datasource.ValoresEncuadernado.Papel));
            this.panelEncuadernado.Children.Add(this.GetPanelInformaciob("Tintas: ", this.Datasource.ValoresEncuadernado.Tintas));
            this.panelEncuadernado.Children.Add(this.GetPanelInformaciob("Acabados: ", "Ninguno"));
            this.lblTiraje.Content = this.Datasource.Tiraje.ToString();
            this.lblCostoPapel.Content = this.Datasource.ValoresCostoTotal.CostoTotalPliegos.ToString("N2");
            this.lblCostoimprenta.Content = this.Datasource.ValoresCostoTotal.CostoTotalImprenta.ToString("N2");
            this.lblCostoTotal.Content = this.Datasource.ValoresCostoTotal.CostoTotaCotizado.ToString("N2");
        }

        private StackPanel GetPanelInformaciob(string titulo, string contenido, bool marginButtom = false)
        {
            var chPanel = new StackPanel { Orientation = Orientation.Horizontal, };
            var lblTitulo = new Label() { Content = titulo, FontWeight = FontWeights.Bold, Foreground = new SolidColorBrush(Colors.White) };
            var lblContenido = new Label() { Content = contenido, Foreground = new SolidColorBrush(Colors.White) };
            if (marginButtom)
            {
                chPanel.Margin = new Thickness(0, 0, 0, 20);
            }
            chPanel.Children.Add(lblTitulo);
            chPanel.Children.Add(lblContenido);
            return chPanel;
        }
    }
}
